package com.pi.controller;

import com.pi.dao.PublishDao;
import com.pi.po.ReportPO;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

public class PublishController extends HttpServlet{
    @Override
    public void init(ServletConfig config) throws ServletException {
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<ReportPO> reports=null;
        try {
            reports=new PublishDao().selectData();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        PrintWriter printWriter=resp.getWriter();
        if(reports.size()!=0){
            for(ReportPO report:reports){
                printWriter.print(report.getT1());
                printWriter.print(report.getT2());
                printWriter.print(report.getT3());
                printWriter.print(report.getT4());
                printWriter.print(report.getT5());
                printWriter.print(report.getT6());
                printWriter.print(report.getT7());
                printWriter.print(report.getT8());
                printWriter.print(report.getT9());
                printWriter.print(report.getT10());
                printWriter.print(report.getT11());
                printWriter.print(report.getT12());
                printWriter.print(report.getT13());
                printWriter.print(report.getT14());
                printWriter.print(report.getT15());
                printWriter.print(report.getT16());
                printWriter.print(report.getT17());
                printWriter.print(report.getT18());
                printWriter.print(report.getT19());
                printWriter.print(report.getT20());
                printWriter.print(report.getT21());
                printWriter.print(report.getT22());
            }
        }else {
            printWriter.print("无数据");
        }
    }

    @Override
    public void destroy() {
    }
}
